<?php
/**
 * Created by PhpStorm.
 * User: antely
 * Date: 2018/4/26
 * Time: 14:54
 */
namespace  app\api\model;
use app\common\model\Base;
use think\Db;
class Api extends  Base{
    public function _initialize(){
        parent::_initialize();
    }

    public function saveAnchor($data){
        if(!empty($data['id'])){
            $result=Db::connect(config('database.db_config1'))->name('Anchor')->where(['id'=>$data['id']])->update($data);
        }else{
                $insert=[
                    'name'=>$data['name'],
                    'sex'=>$data['sex'],
                    'id_front'=>!empty($data['id_front'])?$data['id_front']:'',
                    'mobile'=>!empty($data['mobile'])?$data['mobile']:'',
                    'id_back'=>!empty($data['id_back'])?$data['id_back']:'',
                    'open_id'=>!empty($data['open_id'])?$data['open_id']:'',
                    'qr_code'=>!empty($data['qr_code'])?$data['qr_code']:'',
                    'addtime'=>time()
                ];
             $result=Db::connect(config('database.db_config1'))->name('Anchor')->insertGetId($insert);
        }
        return $result;
    }

    public function delAnchor($data){
        return Db::connect(config('database.db_config1'))->name('Anchor')->where(['id'=>$data['id']])->update(['status'=>-1]);
    }

    public function takeOpenIdOfMobile($data){
     return Db::connect(config('database.db_config1'))->name('Anchor')->where(['mobile'=>$data['mobile']])->value('open_id');
    }

    public function bandMobile($data){
        $updata=[
            'mobile'=>$data['mobile'],
            'open_id'=>$data['openId'],
            'status'=>1,
            'bandtime'=>time()
        ];
        return Db::connect(config('database.db_config1'))->name('Anchor')->where(['id'=>$data['uid']])->update($updata);
    }

    public function bandUser($data){
        $insert=[
            'mobile'=>$data['mobile'],
            'open_id'=>!empty($data['openId'])?$data['openId']:'',
            'name'=>!empty($data['name'])?trim($data['name']):$data['mobile'],
            'sex'=>!isset($data['sex'])?$data['sex']:0,
            'qr_code'=>!empty($data['qr_code'])?$data['qr_code']:"",
            'head_photo'=>!empty($data['head_photo'])?$data['head_photo']:"",
            'signature'=>!empty($data['signature'])?$data['signature']:'点我点我点我关注，爱你哦',
            'weight'=>!empty($data['weight'])?$data['weight']:'55',
            'height'=>!empty($data['height'])?$data['height']:'178',
            'bust'=>!empty($data['bust'])?$data['bust']:'75',
            'waist'=>!empty($data['waist'])?$data['waist']:'64',
            'hip'=>!empty($data['hip'])?$data['hip']:'89',
            'status'=>1,
            'addtime'=>time(),
            'bandtime'=>time()
        ];
        return Db::connect(config('database.db_config1'))->name('Anchor')->insertGetId($insert);
    }

    public function updataMobile($data){
        return Db::connect(config('database.db_config1'))->name('Anchor')->where(['id'=>$data['uid']])->update(['mobile'=>$data['mobile']]);
    }
    
}